package cn.huangsm.advance.designmode.factorymode.abstractfactory;

/**
 * 抽象工厂模式
 * @author huang
 * @PACKAGE_NAME cn.huangsm.advance.designmode.factorymode.abstractfactory
 * @PROJECT_NAME advance-code
 * @date 2019/1/24
 */
public class Factory {
    /**
     * 抽象工厂类
     */
    public static abstract class  AbstractFactory{
        public abstract Vehicle createVehicle();
        public abstract Weapon createWeapon();
        public abstract Food createFood();
    }

    /**
     * 具体工厂类，其中Food，Vehicle，Weapon是抽象类
     */
    public static class DefaultFactory extends AbstractFactory{

        @Override
        public Vehicle createVehicle() {
            return new OO();
        }

        @Override
        public Weapon createWeapon() {
            return new HEHE();
        }

        @Override
        public Food createFood() {
            return new HAHA();
        }
    }
    public interface Vehicle{
        void run();
    }
    public interface Weapon{
        void run();
    }
    public interface Food{
        void run();
    }
    public static class OO implements Vehicle{
      @Override
      public void run(){
          System.out.println("OO");
      }
    }
    public static class HEHE implements Weapon{
        @Override
        public void run(){
            System.out.println("HEHE");
        }
    }
    public static class HAHA implements Food{
        @Override
        public void run(){
            System.out.println("HAHA");
        }
    }

    public static void main(String[] args) {
        AbstractFactory f=new DefaultFactory();
        Vehicle v=f.createVehicle();
        v.run();
        Food food=f.createFood();
        food.run();
        Weapon w=f.createWeapon();
        w.run();
    }
}
